package rs.thread.processor;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

import rs.domain.Track;
import rs.parser.SimilarArtistParser;
import rs.thread.OnerousProcessor;
import rs.util.Requester;
import rs.util.TuningParameters;

/* Classe che, dato un brano, recupera gli artisti simili all'artista di quel brano. */
public class SimilarArtistProcessor implements OnerousProcessor<Track> {
	
	private ConcurrentLinkedQueue<String> similar_artists;
	private SimilarArtistParser parser;
	
	public SimilarArtistProcessor() {
		this.similar_artists = new ConcurrentLinkedQueue<String>();
		this.parser = new SimilarArtistParser();
	}
	
	@Override
	public void onerousFunction(Requester app, Track t) {
		String url = 
				"http://ws.audioscrobbler.com/2.0/?" +
				"method=artist.getsimilar&" +
				"artist=" + t.getArtist() + "&" +
				"limit=" + TuningParameters.SIMILAR_ARTIST_LIMIT + "&" +
				"api_key=8cfeab56c4060f4c3b983902e3903a80&" +
				"format=json";
		String response = app.send(url);
		List<String> artists = this.parser.parse(response);
		this.similar_artists.addAll(artists);
	}
	
	public List<String> getResult() {
		return new ArrayList<String>(this.similar_artists);
	}
	
}